package com.csj.lc.controller;

import com.csj.lc.base.BaseController;
import com.csj.lc.entity.DeviceInfoBean;
import com.csj.lc.entity.dto.ReturnDTO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;

@Controller
@RequestMapping("/device/")
public class DeviceController extends BaseController {

    @RequestMapping("requireTest")
    public void requireUpdateHSDB(HttpServletRequest request, Model model,
                                  @RequestParam String devName, @RequestParam String devId) throws InterruptedException, IOException {


//        deviceService.requireUpdateHSDB( userService.getCurrentUserId(request) , devId ,devName);
    }


    @RequestMapping("onlineList")
    public String onlineList(HttpServletRequest request ,
                             Model model,
                             @RequestParam(required = false,defaultValue = "1") int pageNo){

        return deviceService.onlineList( userService.getCurrentUserId(request), model, pageNo);
    }

    @RequestMapping("info")
    @ResponseBody
    public DeviceInfoBean detail(HttpServletRequest request ,Model model, @RequestParam String devId){

        return deviceService.getDeviceInfo(userService.getCurrentUserId(request), devId);
    }

    @RequestMapping("hsPage")
    public String hardwareSetPage(HttpServletRequest request ,  Model model, @RequestParam String devId)  {

        return deviceService.hardwareSetPage(model,devId);
    }

    @RequestMapping("requireUpdateHardwareSet")
    @ResponseBody
    public ReturnDTO requireUpdateHardwareSet(HttpServletRequest request ,  Model model,@RequestParam String devName,
                                              @RequestParam String devId) throws InterruptedException, IOException {

        return deviceService.requireUpdateHardwareSet( userService.getCurrentUserId(request) , devId ,devName);
    }

    @RequestMapping("lcPage")
    public String lightControllerPage(HttpServletRequest request ,  Model model, @RequestParam String devId)  {

        return deviceService.lightControllerPage(model,devId);
    }

    @RequestMapping("requireUpdateLC")
    @ResponseBody
    public ReturnDTO requireUpdateLC(HttpServletRequest request
            , Model model
            , @RequestParam String devId
            , @RequestParam ArrayList<String> sceneData
    ) throws InterruptedException, IOException {

        return deviceService.requireUpdateLC( userService.getCurrentUserId(request) , devId , sceneData );
    }

    @RequestMapping("ccPage")
    public String ccPage(HttpServletRequest request, Model model, @RequestParam String devId)  {

        return deviceService.ccPage(model,devId);
    }

    @RequestMapping("requireUpdateCC")
    @ResponseBody
    public ReturnDTO requireUpdateCC(HttpServletRequest request
            , Model model
            , @RequestParam String devId
            , @RequestParam int protocolId
    ) throws InterruptedException, IOException {

        return deviceService.requireUpdateCC( userService.getCurrentUserId(request) , devId , protocolId );
    }


    @RequestMapping("requireUpdateFirmware")
    @ResponseBody
    public ReturnDTO requireUpdateFirmware(HttpServletRequest request ,  Model model,
                                   @RequestParam String devId) throws InterruptedException, IOException {

        return deviceService.requireUpdateFirmware( userService.getCurrentUserId(request) , devId);
    }

    @RequestMapping("updateProgress")
    @ResponseBody
    public ReturnDTO<Integer> updateProgress(HttpServletRequest request ,@RequestParam String devId){

        return deviceService.updateProgress(devId);
    }







}
